<div class="state">
	<ul>
		<li class="on">
			<i>1</i>
			<p>购物车</p>
		</li>
		<li>
			<i>2</i>
			<p>填写核对订单信息</p>
		</li>
		<li>
			<i>3</i>
			<p>提交订单成功</p>
		</li>
		<li>
			<i>4</i>
			<p>完成</p>
		</li>
	</ul>
</div>
<hr class="mt30">
<table class="layui-table layui-form" lay-skin="nob" >
	<colgroup>
		<col width="80">
		<col>
		<col width="100">
		<col width="160">
		<col width="140">
	</colgroup>
  <thead>
    <tr class="no-bg">
      <th><input type="checkbox" name="" title="全选" lay-skin="primary"></th>
      <th>商品信息</th>
      <th>投放周期</th>
      <th>成交总价</th>
      <th>操作</th>
    </tr> 
  </thead>
</table>

<?php foreach($data['cartdata'] as $cart){ ?>  
	<table class="layui-table border mt15 layui-form" lay-skin="nob">
	 <colgroup>
		<col width="40">
		<col>
		<col width="100">
		<col width="160">
		<col width="140">
	  </colgroup>
	  <thead>
	    <tr class="bg-gray">
	      <th colspan="8">商家：<?= $cart['seller'] ?></th>
	    </tr> 
	  </thead>
	  <tbody>	
		<?php foreach($cart['goods'] as $goods){ ?>
		<tr>
		  <td><input class="qx"  type="checkbox" name="" lay-skin="primary"></td>
		  <td>
			  <div class="bui-box">
				  <div><a href="/goodsdetail?goods_id=<?= $goods['goods_id'] ?>"><img src="<?= $backend_server.$goods['img'] ?>"/></a></div>
				  <div class="span1 ml15">
					  <a href="/goodsdetail?goods_id=<?= $goods['goods_id'] ?>"><?= $goods['goodsname'] ?></a>
					  <p class="mt15">位置租金：<strong class="f14 red">¥ <?= $goods['price'] ?></strong></p>
					  <p class="mt10">安装维护：<strong class="f14 red">¥ <?= $goods['total_price'] ?></strong></p>
				  </div>
			  </div>
			</td>
		  <td><?= $goods['nums'] ?>个月</td>
		  <td class="red">¥<strong class="f14"><?= $goods['total_price'] ?></strong></td>
		  <td><a class="layui-btn layui-btn-xs layui-btn-warm goods-delete" data-goodsid="<?= $goods['id']?>">删除</a> </td>
		</tr>			
		<?php } ?>		
	  </tbody>
	</table>
<?php } ?>
	
<div class="bui-box-align-middle layui-form">
	<div><input class="quanxuan" type="checkbox" title="全选" lay-skin="primary"></div>
	<div class="span1 ml30">一共购买了3件商品</div>
	<div class="mr30">总计：284元</div>
	<a class="layui-btn  layui-btn-danger buy-submit" data-havepackage="0" data-goodsid="<?= $goods['id']?>">去结算</a>
</div>


<script>
	$(".quanxuan").click(function(){//给全选按钮加上点击事件
		var xz = $(this).prop("checked");//判断全选按钮的选中状态
		var ck = $(".qx").prop("checked",xz);  //让class名为qx的选项的选中状态和全选按钮的选中状态一致。  
		});
		
		$('.buy-submit').on('click',function(){
		    //var package_info = []
		    var goods = [];
		    if($(this).attr('data-havepackage')==0){
		        goods.push([$(this).attr('data-goodsid'),$(this).attr('data-havepackage'),$('#num').val()]);
		    }else{
		        var goods_package_string = $('.package-selected').attr('data-id')+','+$('#num').val()+';';
		        //package_info.push(goods_package_string)
		        //var goods = [$(this).attr('data-goodsid'),$('#num').val(),package_info];
		        goods.push([$(this).attr('data-goodsid'),$(this).attr('data-havepackage'),goods_package_string]);
		    }
		    
		    
		    $params = JSON.stringify({'goods_info':goods});
		    console.log($params);
		    $buy_back = ajaxSynchroPostRequest("/order/create/index",$params);
		    console.log($buy_back);
		    if($buy_back.success==1){
		        layer.msg($buy_back.msg);
		    }else{
		        layer.msg($buy_back.msg);
		    }
		});
</script>
